[#include "/common/macro/header.ftl" /]
[@header title="教师管理" /]
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table id="LAY-user-teacher-table" lay-filter="LAY-user-teacher-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="LAY-user-teacher-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view"><i
                class="layui-icon layui-icon-search"></i></a>
</script>
<script type="text/html" id="LAY-user-teacher-table-status-tpl">
    {{# if(d.enabled) { }}
    <button class="layui-btn layui-btn-sm">在职</button>
    {{# } else { }}
    <button class="layui-btn layui-btn-danger layui-btn-sm">已退休</button>
    {{# } }}
</script>

<script src="${base}/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${base}/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , response = setter.response
            , table = layui.table
            , view = layui.view;

        table.render({
            elem: '#LAY-user-teacher-table'
            , url: '${base}/admin/teachers'
            , response: {
                statusCode: 20000 //成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度
            , page: true
            , cols: [[
                {field: 'name', title: '教师姓名', sort: true}
                , {field: 'phone', title: '手机号', sort: true}
                , {
                    field: 'email',
                    title: '邮箱地址',
                    sort: true
                }, {
                    field: 'enabled',
                    title: '是否在职',
                    sort: true,
                    templet: '#LAY-user-teacher-table-status-tpl'
                }, {
                    title: '操作',
                    align: 'center',
                    fixed: 'right',
                    toolbar: '#LAY-user-teacher-table-bar',
                    unresize: true
                }
            ]]
        });

        //监听工具条
        table.on('tool(LAY-user-teacher-table)', function (obj) {
            if (obj.event === 'view') {
                admin.popup({
                    id: 'LAY-popup-log-view' //定义唯一ID，防止重复弹出
                    , area: ['800px', '80%']
                    , title: '日志详情'
                    , success: function () {
                        //将 views 目录下的某视图文件内容渲染给该面板
                        layui.view(this.id).render('system/log/view', {
                            id: obj.data.id
                        });
                    }
                });
            }
        });

        $('.LAY-list-btns .layui-btn').on('click', function () {
            var othis = $(this)
                , thisEvent = othis.data('events')
                , type = othis.data('type');
            events[thisEvent] && events[thisEvent].call(this, othis, type);
        });
    });
</script>
</body>
</html>
